//
//  CommonViewController.m
//  tcpoctest
//
//  Created by gump on 10/22/12.
//  Copyright (c) 2012 gump. All rights reserved.
//

#import "CommonViewController.h"
#import "WFLabel_blackShadow.h"
#import "FXLabel.h"

@interface CommonViewController ()

@end

@implementation CommonViewController

- (id)init
{
    self = [super init];
    if (self) {
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    [self initUI];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIDeviceOrientationPortrait);
}

-(void)initUI
{
    self.vctype = VI_NULL;
}

-(void)IsModifySucess:(bool)bsuccess
{
    
}

-(void)createTitle
{
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bgColor.png"]];
    
    FXLabel * labelTmp = [[FXLabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    self.mtitle = labelTmp;
    self.mtitle.textAlignment = NSTextAlignmentCenter;
    self.mtitle.font = [UIFont fontWithName:@"Helvetica-Bold" size:21.0];
    self.mtitle.textColor = [UIColor whiteColor];
    self.mtitle.backgroundColor = [UIColor clearColor];
    self.mtitle.shadowOffset = CGSizeMake(0.0f, 8.0f);
    self.mtitle.shadowColor = [UIColor colorWithWhite:0.0f alpha:0.75f];
    self.mtitle.shadowBlur = 5.0f;
    
    UINavigationBar *navBarTmp = [[UINavigationBar alloc]init];
    navBarTmp.barStyle = UIBarStyleBlack;

    UIImage *shadow = [UIImage imageNamed:@"NavigationBarShadow"];
    UIImageView *shadowView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -3, 320, 6)];
    shadowView.image = shadow;

    UIImage *navBarBackground = [UIImage imageNamed:@"NavigationBar"];
    [navBarTmp setBackgroundImage:navBarBackground forBarMetrics:UIBarMetricsDefault];
    [navBarTmp addSubview:self.mtitle];
    
    UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@""];
    self.navItem = item;
    [navBarTmp pushNavigationItem:self.navItem animated:NO];
    //[item release];
    
    self.navBar = navBarTmp;
    [self.navBar sizeToFit];
    [self.view addSubview:self.navBar];
    [self.view addSubview:shadowView];
    //[navBarTmp release];
    //[shadowView release];
    //[labelTmp release];
}

- (UIBarButtonItem *)createBarBackButtonItemWithTitle:(NSString *)title target:(id)target action:(SEL)action {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *buttonImage = [[UIImage imageNamed:@"BarBackButtonNormal"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12, 0, 5)];
    UIImage *buttonPressedImage = [[UIImage imageNamed:@"BarBackButtonNormal"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12, 0, 5)];
    
    [[button titleLabel] setFont:[UIFont boldSystemFontOfSize:12.0]];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [button setTitleShadowColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [button setTitleShadowColor:[UIColor darkGrayColor] forState:UIControlStateHighlighted];
    [button.titleLabel setShadowOffset:CGSizeMake(0, -1)];
    
    CGRect frame = [button frame];
    title = [NSString stringWithFormat:@"  %@", title]; // trick.
    frame.size.width = [title sizeWithFont:[UIFont boldSystemFontOfSize:12.0]].width + 18.0;
    frame.size.height = buttonImage.size.height;
    button.frame = frame;
    [button setBackgroundImage:buttonImage forState:UIControlStateNormal];
    [button setBackgroundImage:buttonPressedImage forState:UIControlStateHighlighted];
    [button setTitle:title forState:UIControlStateNormal];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return [[UIBarButtonItem alloc] initWithCustomView:button];
}

- (UIBarButtonItem *)createBarButtonItemWithTitle:(NSString *)title target:(id)target action:(SEL)action {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *buttonImage = [[UIImage imageNamed:@"BarButtonNormal"] resizableImageWithCapInsets:UIEdgeInsetsMake(4, 4, 4, 4)];
    UIImage *buttonPressedImage = [[UIImage imageNamed:@"BarButtonPressed"] resizableImageWithCapInsets:UIEdgeInsetsMake(4, 4, 4, 4)];
    
    [button.titleLabel setFont:[UIFont boldSystemFontOfSize:12.0]];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [button setTitleShadowColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [button setTitleShadowColor:[UIColor darkGrayColor] forState:UIControlStateHighlighted];
    [button.titleLabel setShadowOffset:CGSizeMake(0, -1)];
    
    CGRect frame = [button frame];
    frame.size.width = [title sizeWithFont:[UIFont boldSystemFontOfSize:12.0]].width + 30.0;
    frame.size.height = buttonImage.size.height;
    button.frame = frame;
    [button setBackgroundImage:buttonImage forState:UIControlStateNormal];
    [button setBackgroundImage:buttonPressedImage forState:UIControlStateHighlighted];
    [button setTitle:title forState:UIControlStateNormal];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return [[UIBarButtonItem alloc] initWithCustomView:button];
}

- (UIBarButtonItem *)createBarButtonItemWithImage:(UIImage *)image target:(id)target action:(SEL)action {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *buttonImage = [[UIImage imageNamed:@"BarButtonNormal"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 4)];
    UIImage *buttonPressedImage = [[UIImage imageNamed:@"BarButtonPressed"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 4)];
    
    CGRect frame = CGRectZero;
    frame.size.width = image.size.width + 25.0;
    frame.size.height = buttonImage.size.height;
    button.frame = frame;
    [button setImage:image forState:UIControlStateNormal];
    [button setBackgroundImage:buttonImage forState:UIControlStateNormal];
    [button setBackgroundImage:buttonPressedImage forState:UIControlStateHighlighted];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return [[UIBarButtonItem alloc] initWithCustomView:button];
}

-(void)UILogicTick
{
    [self UICustomTick];
}

-(void)viewWillHide
{
    
}

-(void)viewWillShow
{
    
}

-(void)refreshView
{
    
}

-(void)WarnningNetBreak
{
    [[ViewManager sharedViewManager] showFailHUDWithStatus:@"当前没有网络耶"
                                                 withDelay:2
                                                  withView:self.view];
}

-(void)WarnningServerBreak
{
    [[ViewManager sharedViewManager] showFailHUDWithStatus:@"网络故障，请检查当前网络"
                                                 withDelay:2
                                                  withView:self.view];
}

-(void)UICustomTick
{
    
}

-(void)cleanUI
{
    
}

@end
